'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Employee = app.model.define('employee', {
    employeeId: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'employee_id',
      comment: '员工编号'
    },
    enterpriseId: {
      type: INTEGER,
      allowNull: false,
      field: 'enterprise_id',
      comment: '企业编号'
    },
    employeeName: {
      type: STRING(50),
      allowNull: false,
      field: 'employee_name',
      comment: '员工姓名'
    },
    phone: {
      type: STRING(20),
      allowNull: true,
      comment: '电话'
    },
    hireTime: {
      type: DATE,
      allowNull: false,
      field: 'hire_time',
      comment: '入职时间'
    },
    employeeStatus: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'active',
      field: 'employee_status',
      comment: '员工状态：active-在职，inactive-离职'
    },
    position: {
      type: STRING(100),
      allowNull: true,
      comment: '职位'
    },
    department: {
      type: STRING(100),
      allowNull: true,
      comment: '部门'
    }
  }, {
    tableName: 'employee',
    timestamps: false,
    comment: '员工表'
  });

  // 定义关联关系
  Employee.associate = function() {
    // 员工属于企业
    app.model.Employee.belongsTo(app.model.Enterprise, {
      foreignKey: 'enterpriseId',
      targetKey: 'enterpriseId',
      as: 'enterprise'
    });
  };

  return Employee;
};











































